package com.wrupple.vegetate.server.domain;

import java.io.Serializable;
import java.util.List;

import com.wrupple.vegetate.domain.FieldDescriptor;

/**
 * 
 * 
 * @author japi
 * 
 */
public class FieldDescriptorImpl implements Serializable, FieldDescriptor {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2502990328355666825L;
	/**FieldDescriptor
	 * With the current implementation, this will NEVER be null
	 */
	private Relation relation;
	private String id, name, widget,defaultValue,dataType;
	private boolean sortable=false,ephemeral=false,filterable = false, createable = true, writeable = true, editable = true, detailable = true,
			summary = true;

	/**
	 * @return the summary
	 */
	public boolean isSummary() {
		return summary;
	}

	/**
	 * @param summary
	 *            the summary to set
	 */
	public void setSummary(boolean summary) {
		this.summary = summary;
	}

	/**
	 * @return the machine readable name of this field (identicall to the java
	 *         property name)
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name of the field
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the widget
	 */
	public String getWidget() {
		return widget;
	}

	/**
	 * @param widget
	 *            the widget to set
	 */
	public void setWidget(String widget) {
		this.widget = widget;
	}

	/**
	 * @return the filterable
	 */
	public boolean isFilterable() {
		return filterable;
	}

	/**
	 * @param filterable
	 *            the filterable to set
	 */
	public void setFilterable(boolean filterable) {
		this.filterable = filterable;
	}

	/**
	 * @return the createable
	 */
	public boolean isCreateable() {
		return createable;
	}

	/**
	 * @param createable
	 *            the createable to set
	 */
	public void setCreateable(boolean createable) {
		this.createable = createable;
	}

	/**
	 * @return the writeable
	 */
	public boolean isWriteable() {
		return writeable;
	}

	/**
	 * @param writeable
	 *            the writeable to set
	 */
	public void setWriteable(boolean writeable) {
		this.writeable = writeable;
	}

	/**
	 * @return the editable
	 */
	public boolean isEditable() {
		return editable;
	}

	/**
	 * @param editable
	 *            the editable to set
	 */
	public void setEditable(boolean editable) {
		this.editable = editable;
	}

	/**
	 * @return the detailable
	 */
	public boolean isDetailable() {
		return detailable;
	}

	/**
	 * @param detailable
	 *            the detailable to set
	 */
	public void setDetailable(boolean detailable) {
		this.detailable = detailable;
	}


	public void setRelation(Relation relation) {
		this.relation = relation;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "FieldDescriptor [createable=" + createable + ", detailable=" + detailable + ", editable=" + editable
				+ ", filterable=" + filterable + ", id=" + id + ", name=" + name + ", widget=" + widget
				+ ", writeable=" + writeable + "]";
	}

	/**
	 * @return the value used to fill out this entry 
	 */
	public String getDefaultValue() {
		return defaultValue;
	}

	/**
	 * @param defaultValue the value used to fill out this entry
	 */
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	@Override
	public String getForeignCatalog() {
		if(this.relation==null){
			return null;
		}
		return relation.getCatalog();
	}

	@Override
	public List<String> getDefaultValueOptions() {
		if(this.relation==null){
			return null;
		}
		return relation.getOptions();
	}

	@Override
	public boolean isKey() {
		if(this.relation==null){
			return false;
		}
		return relation.isKey();
	}

	@Override
	public boolean isEphemeral() {
		return ephemeral;
	}


	public void setEphemeral(boolean ephemeral) {
		this.ephemeral = ephemeral;
	}

	@Override
	public String getDataType() {
		return dataType;
	}

	@Override
	public boolean isSortable() {
		return sortable;
	}

	/**
	 * @param dataType the dataType to set
	 */
	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	/**
	 * @param sortable the sortable to set
	 */
	public void setSortable(boolean sortable) {
		this.sortable = sortable;
	}


}
